package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.cart.bmo.inoutOrderProduct.IDeleteInoutOrderProductBMO;
import com.java110.mall.cart.bmo.inoutOrderProduct.ISaveInoutOrderProductBMO;
import com.java110.mall.cart.bmo.inoutOrderProduct.IUpdateInoutOrderProductBMO;
import com.java110.po.inoutOrder.InoutOrderProductPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/inoutOrderProduct")
public class InoutOrderProductApi {

    @Autowired
    private ISaveInoutOrderProductBMO saveInoutOrderProductBMOImpl;
    @Autowired
    private IUpdateInoutOrderProductBMO updateInoutOrderProductBMOImpl;
    @Autowired
    private IDeleteInoutOrderProductBMO deleteInoutOrderProductBMOImpl;


    /**
     * 微信保存消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /inoutOrderProduct/saveInoutOrderProduct
     * @path /app/inoutOrderProduct/saveInoutOrderProduct
     */
    @RequestMapping(value = "/saveInoutOrderProduct", method = RequestMethod.POST)
    public ResponseEntity<String> saveInoutOrderProduct(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "prodName", "请求报文中未包含prodName");
        Assert.hasKeyAndValue(reqJson, "valueId", "请求报文中未包含valueId");
        Assert.hasKeyAndValue(reqJson, "price", "请求报文中未包含price");


        InoutOrderProductPo inoutOrderProductPo = BeanConvertUtil.covertBean(reqJson, InoutOrderProductPo.class);
        return saveInoutOrderProductBMOImpl.save(inoutOrderProductPo);
    }

    /**
     * 微信修改消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /inoutOrderProduct/updateInoutOrderProduct
     * @path /app/inoutOrderProduct/updateInoutOrderProduct
     */
    @RequestMapping(value = "/updateInoutOrderProduct", method = RequestMethod.POST)
    public ResponseEntity<String> updateInoutOrderProduct(@RequestBody JSONObject reqJson) {

        InoutOrderProductPo inoutOrderProductPo = BeanConvertUtil.covertBean(reqJson, InoutOrderProductPo.class);
        return updateInoutOrderProductBMOImpl.update(inoutOrderProductPo);
    }

    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /inoutOrderProduct/deleteInoutOrderProduct
     * @path /app/inoutOrderProduct/deleteInoutOrderProduct
     */
    @RequestMapping(value = "/deleteInoutOrderProduct", method = RequestMethod.POST)
    public ResponseEntity<String> deleteInoutOrderProduct(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "communityId", "小区ID不能为空");

        Assert.hasKeyAndValue(reqJson, "itemId", "itemId不能为空");


        InoutOrderProductPo inoutOrderProductPo = BeanConvertUtil.covertBean(reqJson, InoutOrderProductPo.class);
        return deleteInoutOrderProductBMOImpl.delete(inoutOrderProductPo);
    }


}
